import 'package:flutter/material.dart';
import '../../widget/PPBaseWidget.dart';
import './widget/PPConditionKindChoiceView.dart';

// 自定义枚举变量
enum PPConditionChoiceType  {
    sex,
    edu,
    sort,
    wage
}

class PPConditionChoicePage extends StatefulWidget with PPBaseWidget {

    PPConditionChoicePage({Key key}): super();

    _PPConditionChoiceState createState() => _PPConditionChoiceState();
}

class _PPConditionChoiceState extends State {

    List<Map> sexData = [
        {'title': '全部', 'isSelect': true}, 
        {'title': '男生可做', 'isSelect': false},
        {'title': '女生可做', 'isSelect': false}
    ];
    List<Map> eduData = [
        {'title': '全部', 'isSelect': true}, 
        {'title': '学生可做', 'isSelect': false},
        {'title': '非学生可做', 'isSelect': false}, 
        {'title': '高中毕业', 'isSelect': false},
        {'title': '大专毕业', 'isSelect': false}, 
        {'title': '本科以上', 'isSelect': false}
    ];
    List<Map> sortData = [
        {'title': '推荐排序', 'isSelect': true}, 
        {'title': '最新发布', 'isSelect': false},
        {'title': '酬金最高', 'isSelect': false}
    ];
    List<Map> wageData = [
        {'title': '月结', 'isSelect': true}, 
        {'title': '周结', 'isSelect': false},
        {'title': '日结', 'isSelect': false}
    ];

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(title: Text('筛选')),
            body: Container(
                padding: EdgeInsets.fromLTRB(15, 0, 15, 10),
                decoration: BoxDecoration(color: Colors.white10, border: Border(top: BorderSide(color: Color.fromRGBO(238,238,238,1), width: 1, style: BorderStyle.solid))),
                child: SingleChildScrollView(
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                            PPConditionKindChoiceView(title: '性别要求', type: PPConditionChoiceType.sex, data: sexData, action: _onPressButtonActon),
                            PPConditionKindChoiceView(title: '学历要求', type: PPConditionChoiceType.edu, data: eduData, action: _onPressButtonActon),
                            PPConditionKindChoiceView(title: '排序方式', type: PPConditionChoiceType.sort, data: sortData, action: _onPressButtonActon),
                            PPConditionKindChoiceView(title: '薪资周期', type: PPConditionChoiceType.wage, data: wageData, action: _onPressButtonActon)
                        ],
                    ),
                )
            ),
        );
    }

	_onPressButtonActon(type, data, item, index) {
        List<Map> _data = [];
        data.forEach((objc) {
            if(objc['title'] == item['title']) {
                objc['isSelect'] = true;
            } else {
                objc['isSelect'] = false;
            }
            _data.add(objc);
        });
        switch(type) {
            case PPConditionChoiceType.sex: {
                setState(() {
                    sexData = _data;
                    });
                break;
            }
            case PPConditionChoiceType.edu: {
                setState(() {
                    eduData = _data;
                    });
                break;
            }
            case PPConditionChoiceType.sort: {
                setState(() {
                    sortData = _data;
                    });
                break;
            }
            case PPConditionChoiceType.wage: {
                setState(() {
                    wageData = _data;
                    });
                break;
            }
            default: 
        }
	}
}
